from typing import Optional, List
from datetime import date

from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel

from module_admin.annotation.pydantic_annotation import as_query


class FutureSettlementModel(BaseModel):
    """
    期货结算单表对应pydantic模型
    """

    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    id: Optional[int] = Field(default=None, description='结算单id')
    account_code: Optional[str] = Field(default=None, description='账户代码')
    settlement_date: Optional[date] = Field(default=None, description='结算日期')
    settlement_type: Optional[str] = Field(default='D', description='结算单类型：D(日报)、M(月报)')
    profit_calc_type: Optional[str] = Field(default='day', description='盈亏计算方式：day(逐日盯市)、trade(逐笔对冲)')
    file_name: Optional[str] = Field(default=None, description='文件名')
    settlement_status: Optional[str] = Field(default='0', description='结算单状态：0(未下载)、1(已下载)、2(已入库)')
    create_time: Optional[str] = Field(default=None, description='创建时间')
    update_time: Optional[str] = Field(default=None, description='更新时间')


class FutureSettlementDownloadModel(BaseModel):
    """
    期货结算单下载请求模型
    """

    model_config = ConfigDict(from_attributes=True, alias_generator=to_camel, populate_by_name=True)

    username: str = Field(description='用户名')
    password: str = Field(description='密码')
    settlement_date: date = Field(description='结算日期')
    account_code: str = Field(description='账户代码')
    profit_calc_type: str = Field(default='day', description='盈亏计算方式：day(逐日盯市)或trade(逐笔对冲)')
    settlement_type: str = Field(default='D', description='结算单类型：D(日报)或M(月报)')


class BatchFutureSettlementDownloadModel(BaseModel):
    """
    批量下载期货结算单请求模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    account_codes: List[str] = Field(description='账户代码列表')
    begin_date: date = Field(description='开始日期')
    end_date: date = Field(description='结束日期')
    settlement_types: List[str] = Field(description='结算单类型列表')
    profit_calc_types: List[str] = Field(description='盈亏计算方式列表')


@as_query
class FutureSettlementQueryModel(BaseModel):
    """
    期货结算单不分页查询模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    account_code: Optional[str] = Field(default=None, description='账户代码')
    begin_date: Optional[date] = Field(default=None, description='开始日期')
    end_date: Optional[date] = Field(default=None, description='结束日期')
    settlement_type: Optional[str] = Field(default=None, description='结算单类型')
    profit_calc_type: Optional[str] = Field(default=None, description='盈亏计算方式')
    settlement_status: Optional[str] = Field(default=None, description='结算单状态')


@as_query
class FutureSettlementPageQueryModel(FutureSettlementQueryModel):
    """
    期货结算单分页查询模型
    """

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')


class DeleteFutureSettlementModel(BaseModel):
    """
    删除期货结算单请求模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    settlement_ids: List[int] = Field(description='结算单ID列表')


class ImportSettlementToDailyModel(BaseModel):
    """
    导入期货结算单到资金日报请求模型
    """

    # 使用pydantic提供的to_camel函数将下划线命名转换为驼峰命名，以匹配前端参数
    model_config = ConfigDict(from_attributes=True, alias_generator=to_camel, populate_by_name=True)

    id: int = Field(description='结算单ID')
    account_code: str = Field(description='账户代码')
    settlement_date: date = Field(description='结算日期')
    file_name: str = Field(description='文件名')
    settlement_type: str = Field(description='结算单类型：D(日报)、M(月报)')
    profit_calc_type: str = Field(description='盈亏计算方式：day(逐日盯市)、trade(逐笔对冲)')
